package com.codejiwei.flink.json;

import com.alibaba.fastjson2.JSON;
import com.codejiwei.flink.entity.WaterSensor;

/**
 * @author jiwei
 * @description
 * @date 2023/5/22 16:55
 */
public class JsonTest {
    public static void main(String[] args) {

        String jsonString = "{\"id\":\"sensor_2\",\"ts\":1607527997000L,\"vc\":78}";

        Object parse = JSON.parse(jsonString);
        WaterSensor waterSensor2 = JSON.parseObject(jsonString, WaterSensor.class);

        System.out.println(parse);
        System.out.println(waterSensor2);

        System.out.println("-------------------------------------------------------------");

        WaterSensor waterSensor = new WaterSensor("sensor_1", 1607527992000L, 20);
        String s = JSON.toJSONString(waterSensor);
        Object o = JSON.toJSON(waterSensor);
        System.out.println(s);
        System.out.println(o);


    }
}
